<template>
	<view class="page" style="padding-bottom: 50rpx;">
		<view class="topVue">
			<view class="safeVue" :style="{ height: statusBarHeight + 'rpx' }"></view>
			<view class="flex align-center padding-row30" :style="{ height: barHeight + 'rpx', top: statusBarHeight + 'rpx' }" @click="$tools.back()">
				<image src="../../static/back.png" style="width: 48rpx; height: 48rpx;"></image>
				<text style="line-height: 1; color: #454545; font-weight: 600; font-size: 32rpx; padding-left: 20rpx;">服务中</text>
			</view>
		</view>
		<view :style="{ height: statusBarHeight + barHeight + 'rpx' }"></view>
		
		<view class="conVue flex-wrap flex-between margin0">
			<view class="li" v-for="(item, index) in imgs" :key="index">
				<image :src="item" style="width: 100%; height: 100%; border-radius: 20rpx;"></image>
			</view>
			<view class="li relative" @click="choose()" v-if="imgs.length<4">
				<text class="absolute-auto" style="line-height: 1; font-size: 60rpx;">+</text>
			</view>
		</view>
		<view class="item margin20 flex-between align-center padding-row30" @click="show = true">
			<text style="color: #454545; font-weight: 600; line-height: 1;">完成时间</text>
			<view class="flex align-center">
				<text style="color: #454545; font-weight: 600; line-height: 1; padding-right: 20rpx;">{{ time }}</text>
				<image src="../../static/more.png" style="width: 36rpx; height: 36rpx;"></image>
			</view>
		</view>
		<textarea placeholder="完成说明" v-model="remark"></textarea>
		<view class="btn margin50" @click="submitDone()">接单完成上传</view>
		<u-picker v-model="show" mode="time" :params="params" @confirm="confirm"></u-picker>
	</view>
</template>

<script>
	import url from "@/common/url.js"
	import { mapState } from "vuex"
	export default {
		data(){
			return {
				statusBarHeight: 0,
				barHeight: 0,
				tabs: [{name: "红包明细"}, {name: "福利红包"}],
				current: 0,
				imgs: [],
				show: false,
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: false
				},
				time: "",
				remark: "",
				orderId: ""
			}
		},
		onLoad(option) {
			this.orderId = option.value
			console.log(this.orderId)
			let that = this;
			wx.getSystemInfo({
				success(res) {
					let deviceWidth = wx.getSystemInfoSync().windowWidth
					that.statusBarHeight = Number(res.statusBarHeight) * ( 750 / deviceWidth ) 
					let menuButtonInfo = wx.getMenuButtonBoundingClientRect()
					let barHeight = menuButtonInfo.height + (menuButtonInfo.top - res.statusBarHeight) * 2
					that.barHeight = Number(barHeight) * ( 750 / deviceWidth )
				},
			});
		},
		
		computed: {
			...mapState({
				user: state=> state.user
			})
		},
		
		methods: {

			// 上传图片
			choose(){
				this.$utils.choose1().then(res=>{
					console.log(res)
					uni.showLoading()
					let _this = this
					uni.uploadFile({
						url: `${url.url}/api/WeChat/wechatUpload`,
						filePath: res.tempFilePaths[0],
						name: "file",
						header:{
							"token": uni.getStorageSync("token")
						},
						success: (result) => {
							console.log(result)
							uni.hideLoading()
							let data = JSON.parse(result.data)
							_this.imgs.push(data.data)
							console.log(_this.imgs)
						},
						fail(err) {	
							console.log(err)
							uni.hideLoading()
						}
					})
				})
			}, 
			
			// 完成订单
			async submitDone(){
				const res = await this.$request("/api/WeChat/homecareWorkerFinish", {
					workerId: this.user.id,
					id: this.orderId,
					imgUrl: this.imgs.join(","),
					description: this.remark
				}, "POST")
				if(res.code==200) {
					this.$u.toast("操作成功")
					this.imgs = []
					this.time = ""
					this.remark = ""
					setTimeout(()=>{
						this.$tools.back(1)
					}, 1000)
					console.log(res)
				}else{
					this.$u.toast(res.msg)
				}
			},
			
			confirm(e){
				console.log(e)
				this.time = `${e.year}-${e.month}-${e.day} ${e.hour}:${e.minute}`
			},
			
		}
	}
</script>

<style lang="less" scoped>
	.topVue {
		width: 100%;
		background: #fff;
		position: fixed;
		left: 0;
		top: 0;
		z-index: 99;
		.safeVue {
			width: 100%;
		}
	}
	
	.conVue {
		width: 690rpx;
		.li {
			width: 330rpx;
			height: 330rpx;
			border-radius: 20rpx;
			box-shadow: 0rpx 0rpx 16rpx 0rpx rgba(178, 178, 178, 0.25), inset 0rpx 8rpx 8rpx 0rpx rgba(255, 255, 255, 0.25);
			position: relative;
			margin-top: 20rpx;
		}
	}
	
	textarea {
		width: 690rpx;
		height: 200rpx;
		background: #f5f5f5;
		border-radius: 15rpx;
		display: block;
		box-sizing: border-box;
		padding: 20rpx;
		color: #333;
		margin: 20rpx auto 0;
	}
	.item {
		width: 690rpx;
		height: 92rpx;
		border-radius: 20rpx;
		box-shadow: 0rpx 0rpx 16rpx 0rpx rgba(178, 178, 178, 0.25), inset 0rpx 8rpx 8rpx 0rpx rgba(255, 255, 255, 0.25);
		position: relative;
	}
	.btn {
		width: 520rpx;
		height: 88rpx;
		background: #D37430;
		border-radius: 12rpx;
		line-height: 88rpx;
		text-align: center;
		color: #fff;
	}
</style>